//        https://ac.nowcoder.com/acm/problem/230720





#include <iostream>
using namespace std;


int main()
{
	string s;
	cin >> s;

	for (int i = 0; i < s.size() - 1; i++)
		if (s[i] == s[i + 1])
		{
			cout << "2" << endl;
			return 0;
		}

	for (int j = 0; j < s.size() - 2; j++)
		if (s[j] == s[j + 2])
		{
			cout << "3" << endl;
			return 0;
		}

	cout << "-1" << endl;
	return 0;
}